package me.imvc.generate;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import me.imvc.lib.Folder;
import me.imvc.lib.StringToFile;
import me.imvc.generate.template.*;

public class GenerateMvc {
	public static void main(String[] args) {

//=================生成前修改内容=====begin==========================================
		//项目路径
		String projectPath = "D:/eclipse//workspace/imvc/";
		//app包
		String appPath = "src/me/imvc/app/";
		//视图路径
		String viewPath = "WebContent/WEB-INF/views/";
		
		//实体
		String entityClass="Notices";
		String entityName="notice";
		//模型
		String modelClass="AbcModel";		
		String modelName="abc";
		//控制器	
		String controllerPackage="";
		String controllerClass="AbcController";
		//视图
		String viewUrl="abc";
		String view="abc";
		//视图显示数据
		Map<String, String> entityAttributMap = new LinkedHashMap<String, String>();
		entityAttributMap.put("title", "标题");
		entityAttributMap.put("description", "简介");
		entityAttributMap.put("author", "发布者");
		entityAttributMap.put("content", "内容");
//=================生成前修改内容=====end==========================================
		
		//模板数据
		Map<String, Object> templateDataMap = new HashMap<String, Object>();		
		templateDataMap.put("entityClass", entityClass);
		templateDataMap.put("entityName", entityName);
		templateDataMap.put("modelClass", modelClass);
		templateDataMap.put("modelName", modelName);
		templateDataMap.put("controllerPackage", controllerPackage);	
		templateDataMap.put("controllerClass", controllerClass);
		templateDataMap.put("viewUrl", viewUrl);
		templateDataMap.put("view", view);
		templateDataMap.put("entityAttributMap", entityAttributMap);
		
		//生成模型
		ModelTemplate modelTemplate = new ModelTemplate();
		StringToFile.writes(modelTemplate.generate(templateDataMap), projectPath
				+ appPath + "models"+File.separator+modelClass+".java");

		//生成控制器
		ControllerTemplate controllerTemplate = new ControllerTemplate();
		StringToFile.writes(controllerTemplate.generate(templateDataMap), projectPath
				+ appPath + "controllers"+File.separator+controllerClass+".java");

		
		Folder.newFolder(projectPath+viewPath+view);
		//生成视图index
		ViewIndexTemplate viewIndexTemplate = new ViewIndexTemplate();
		StringToFile.writes(viewIndexTemplate.generate(templateDataMap), projectPath
				+ viewPath+view+File.separator+"index.jsp");

		//生成视图search
		ViewSearchTemplate viewSearchTemplate = new ViewSearchTemplate();
		StringToFile.writes(viewSearchTemplate.generate(templateDataMap), projectPath
				+ viewPath+view+File.separator+"search.jsp");

		//生成视图editNew
		ViewEditNewTemplate viewEditNewTemplate = new ViewEditNewTemplate();
		StringToFile.writes(viewEditNewTemplate.generate(templateDataMap), projectPath
				+ viewPath+view+File.separator+"editNew.jsp");

		//生成视图edit
		ViewEditTemplate viewEditTemplate = new ViewEditTemplate();
		StringToFile.writes(viewEditTemplate.generate(templateDataMap), projectPath
				+ viewPath+view+File.separator+"edit.jsp");

		//生成视图show
		ViewShowTemplate viewShowTemplate = new ViewShowTemplate();
		StringToFile.writes(viewShowTemplate.generate(templateDataMap), projectPath
				+ viewPath+view+File.separator+"show.jsp");
		
		System.out.println("生成完成");
	}

}
